/*
 * @lc app=leetcode.cn id=3 lang=golang
 *
 * [3] 无重复字符的最长子串
 */

// @lc code=start
func lengthOfLongestSubstring(s string) int {
	var arr [128]int = [128]int{}
	for i := 0; i < 128; i++ {
		arr[i] = -1
	}
	var max int
	var n int
	var idx int = -1
	for i, ch := range s {
		if arr[ch] <= idx {
			n++
		} else {
			idx = arr[ch]
			if n > max {
				max = n
			}
			n = i - idx
		}
		arr[ch] = i
	}
	if n > max {
		max = n
	}
	return max
}

// @lc code=end

